package cc.telecomdigital.tdstock.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.SystemInfo;
import cc.telecomdigital.tdstock.Framework.Activity_Framework;

/**
 * About "TD Stock" app
 * desc "about.xml"
 * @author ouyangzhihui
 *
 */
public class AboutActivity extends Activity_Framework
{
	private TextView	_about_version;
	private TextView	_about_user_name;
	private TextView	_about_user_number;
	private Button		_btn_close;
	private ScrollView	_scrollview;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);
		
		_about_version = (TextView) findViewById(R.id.about_version);
		_about_user_name = (TextView) findViewById(R.id.about_user_name);
		_about_user_number = (TextView) findViewById(R.id.about_user_number);

		String username = /*getUser();*/((ITDLApplication) getApplicationContext())
				.getUserName(CommonDefn.SYSTEM_TRIAL_ACCOUNT_USER);
		String number = /*getDeviceId();((ITDLApplication) getApplicationContext())
				.getDeviceId() */ SystemInfo.getFormattedAccountId(this.getApplicationContext());
		if (((ITDLApplication) getApplicationContext()).getDataMode() == CommonDefn.DataMode.Delay)
		{
			username = getResources()
					.getString(R.string.trial_delay_version);
			number = "";
		}
		else if (((ITDLApplication) getApplicationContext())
				.isAuthComeFromActivationCode())
		{
			username = getResources().getString(
					R.string.trial_realtime_version);
		}

		_about_version.setText(getAppVersion());
		_about_user_name.setText(username);
		_about_user_number.setText(number);

		_btn_close = (Button) findViewById(R.id.about_close);
		_btn_close.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				AboutActivity.this.setResult(RESULT_OK, getIntent());
				finish();
			}
		});

		_scrollview = (ScrollView) findViewById(R.id.scrollview);
		_scrollview.setScrollbarFadingEnabled(true);
	}

	@Override
	public void onBackPressed()
	{
		   if(_btn_close != null)
		   {
			   _btn_close.performClick();
		   }
	}
	
	
	protected  String  getAppVersion () 
	{
		String result = " -.-.-";
			
			try
			{
				result = getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
				if (appHost.IsDevelopment())
				    result += "_Dev";
			}
            catch (Exception e)
            {
				e.printStackTrace();
			}
			return result;
	}	
}
